/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Jiang Jinxi
 * Date: 2024-04-27
 * Time: 15:25
 */
public class MyRectangle2D {
    private double x;
    private double y;
    private double width;
    private double height;

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }
    public MyRectangle2D(){
        this.x = 0;
        this.y = 0;
        this.height = 1;
        this.width = 1;
    }

    public MyRectangle2D(double x, double y, double width, double height) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }
    public double getArea(){
        return this.height*this.width;
    }
    public double getPerimeter(){
        return this.height*2+this.width*2;
    }
    public boolean contains(double x,double y){
        return Math.abs(this.x-x)<(height/2) && Math.abs(this.y-y)<width/2;
    }
    public boolean contains(MyRectangle2D r) {
        return (height / 2 - Math.abs(this.x - r.x)) > r.height / 2
                && (width / 2 - Math.abs(this.y - r.y)) > r.width / 2;
    }
    public boolean overlaps(MyRectangle2D r){
        if( Math.abs(this.x-r.x)>(height/2)
                && Math.abs(this.y-r.y)>width/2
             && Math.abs(this.x-r.x)<(height/2+r.height/2)
                && Math.abs(this.y-r.y) < (width/2+r.width/2)){
            return true;
        }else if((this.height/2 - Math.abs(this.x-r.x))>(height/2)
            && (this.width/2 - Math.abs(this.y-r.y)) < (width/2)){
            return true;
        }else if((this.height/2 - Math.abs(this.x-r.x))<(height/2)
                && (this.width/2 - Math.abs(this.y-r.y)) > (width/2)){
            return true;
        }
              return false;
    }

}
